﻿Jxstar.currentPage = function() {
	var config = {param:{},initpage:function(page, define){},eventcfg:{}};

	var plantypeData = Jxstar.findComboData('plantype');
	var moneytypeData = Jxstar.findComboData('moneytype');
	var authtypeData = Jxstar.findComboData('authtype');
	var yesnoData = Jxstar.findComboData('yesno');
	var planyearData = Jxstar.findComboData('planyear');
	var planstatusData = Jxstar.findComboData('planstatus');

	var cols = [
	{col:{header:'计划编号', width:100, sortable:true}, field:{name:'money_plan__plan_code',type:'string'}},
	{col:{header:'项目名称', width:185, sortable:true}, field:{name:'money_plan__plan_name',type:'string'}},
	{col:{header:'主要内容与申请理由', width:260, sortable:true, hidden:true}, field:{name:'money_plan__plan_desc',type:'string'}},
	{col:{header:'计划类型', width:78, sortable:true, hidden:true, align:'center',
		renderer:function(value){
			for (var i = 0; i < plantypeData.length; i++) {
				if (plantypeData[i][0] == value)
					return plantypeData[i][1];
			}
		}}, field:{name:'money_plan__plan_type',type:'string'}},
	{col:{header:'项目类别', width:92, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: moneytypeData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: moneytypeData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < moneytypeData.length; i++) {
				if (moneytypeData[i][0] == value)
					return moneytypeData[i][1];
			}
		}}, field:{name:'money_plan__money_type',type:'string'}},
	{col:{header:'型号规格', width:100, sortable:true}, field:{name:'money_plan__device_size',type:'string'}},
	{col:{header:'计量单位', width:58, sortable:true}, field:{name:'money_plan__plan_unit',type:'string'}},
	{col:{header:'数量', width:51, sortable:true, renderer:JxUtil.formatNumber(2)}, field:{name:'money_plan__plan_num',type:'float'}},
	{col:{header:'单价(万元)', width:73, sortable:true, renderer:JxUtil.formatNumber(2)}, field:{name:'money_plan__plan_price',type:'float'}},
	{col:{header:'预计总投资(万元)', width:114, sortable:true, renderer:JxUtil.formatNumber(2)}, field:{name:'money_plan__plan_money',type:'float'}},
	{col:{header:'当年预计付款(万元)', width:129, sortable:true, renderer:JxUtil.formatNumber(2)}, field:{name:'money_plan__year_money',type:'float'}},
	{col:{header:'授权时间', width:100, sortable:true, renderer:function(value) {
			return value ? value.format('Y-m-d') : '';
		}}, field:{name:'money_plan__auth_date',type:'date'}},
	{col:{header:'授权形式', width:100, sortable:true, align:'center',
		editable:true,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: authtypeData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false, allowBlank:false,
			value: authtypeData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < authtypeData.length; i++) {
				if (authtypeData[i][0] == value)
					return authtypeData[i][1];
			}
		}}, field:{name:'money_plan__auth_type',type:'string'}},
	{col:{header:'实施单位', width:114, sortable:true}, field:{name:'money_plan__done_deptname',type:'string'}},
	{col:{header:'授权登记人', width:75, sortable:true}, field:{name:'money_plan__auth_user',type:'string'}},
	{col:{header:'是否结转', width:60, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: yesnoData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: yesnoData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < yesnoData.length; i++) {
				if (yesnoData[i][0] == value)
					return yesnoData[i][1];
			}
		}}, field:{name:'money_plan__is_turn',type:'string'}},
	{col:{header:'预计实施时间', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_period',type:'string'}},
	{col:{header:'立项批复文号', width:100, sortable:true}, field:{name:'money_plan__project_fileno',type:'string'}},
	{col:{header:'立项批复金额(万元)', width:121, sortable:true, renderer:JxUtil.formatNumber(2)}, field:{name:'money_plan__project_money',type:'float'}},
	{col:{header:'合同金额(万元)', width:100, sortable:true, hidden:true, renderer:JxUtil.formatNumber(2)}, field:{name:'money_plan__money_contract',type:'float'}},
	{col:{header:'已付款金额(万元)', width:120, sortable:true, hidden:true, renderer:JxUtil.formatNumber(2)}, field:{name:'money_plan__money_pay',type:'float'}},
	{col:{header:'预算年度', width:64, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: planyearData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: planyearData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < planyearData.length; i++) {
				if (planyearData[i][0] == value)
					return planyearData[i][1];
			}
		}}, field:{name:'money_plan__plan_year',type:'string'}},
	{col:{header:'申报日期', width:82, sortable:true, renderer:function(value) {
			return value ? value.format('Y-m-d') : '';
		}}, field:{name:'money_plan__plan_date',type:'date'}},
	{col:{header:'申报人', width:73, sortable:true}, field:{name:'money_plan__plan_user',type:'string'}},
	{col:{header:'申报部门', width:100, sortable:true}, field:{name:'money_plan__dept_name',type:'string'}},
	{col:{header:'计划状态', width:90, sortable:true, align:'center',
		editable:false,
		editor:new Ext.form.ComboBox({
			store: new Ext.data.SimpleStore({
				fields:['value','text'],
				data: planstatusData
			}),
			emptyText: jx.star.select,
			mode: 'local',
			triggerAction: 'all',
			valueField: 'value',
			displayField: 'text',
			editable:false,
			value: planstatusData[0][0]
		}),
		renderer:function(value){
			for (var i = 0; i < planstatusData.length; i++) {
				if (planstatusData[i][0] == value)
					return planstatusData[i][1];
			}
		}}, field:{name:'money_plan__plan_status',type:'string'}},
	{col:{header:'备注', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_memo',type:'string'}},
	{col:{header:'主键', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_id',type:'string'}},
	{col:{header:'申报人ID', width:100, sortable:true, hidden:true}, field:{name:'money_plan__plan_userid',type:'string'}},
	{col:{header:'申报部门ID', width:100, sortable:true, hidden:true}, field:{name:'money_plan__dept_id',type:'string'}},
	{col:{header:'实施部门ID', width:100, sortable:true, hidden:true}, field:{name:'money_plan__done_deptid',type:'string'}},
	{col:{header:'授权人登记id', width:100, sortable:true, hidden:true, defaultval:'fun_getUserId()'}, field:{name:'money_plan__auth_userid',type:'string'}}
	];
	
	config.param = {
		cols: cols,
		sorts: null,
		hasQuery: '1',
		isedit: '1',
		isshow: '1',
		funid: 'money_auth'
	};
	
	config.eventcfg = {				moreAuth: function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selected(records)) return;						var planids = '';			for (var i = 0; i < records.length; i++) {				var planid = records[i].get('money_plan__plan_id');				planids += '&keyid=' + planid			}						this.createAuthWindow(planids);		},				exeAuth: function(planids, form) {						var params = 'funid=money_auth' + planids;			params += JxUtil.getFormValues(form, false);			params += '&pagetype=editgrid&eventcode=moreAuth';						var self = this;			var endcall = function(data) {				//重新加载数据				self.grid.getStore().reload();			};			//发送请求			Request.postRequest(params, endcall);		},				/**		* private 创建报表选项对话框		*		* planids -- 批量选择的投资计划ID		**/		createAuthWindow: function(planids) {			var authtypeData = Jxstar.findComboData('authtype');					var printForm = new Ext.form.FormPanel({				id: 'node_money_auth_form',				style: 'padding:20px;',				border: false,				frame: false,				baseCls: 'x-plain',				items: [{					anchor:'100%',					border: false,					layout:'column',					autoHeight:true,					items:[{						border:false,						columnWidth:0.5,						layout:'form',						style: 'padding-left:10px;',						items:[							{xtype:'combo', fieldLabel:'授权形式', name:'money_plan__auth_type', defaultval:'ty',								anchor:'100%', editable:false, allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*',								store: new Ext.data.SimpleStore({									fields:['value','text'],									data: authtypeData								}),								emptyText: jx.star.select,								mode: 'local',								triggerAction: 'all',								valueField: 'value',								displayField: 'text',								value: authtypeData[0][0]},							{xtype:'datefield', fieldLabel:'授权时间', name:'money_plan__auth_date', defaultval:'fun_getToday()', format:'Y-m-d', allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', anchor:'100%', readOnly:true},							{xtype:'hidden', fieldLabel:'授权人id', name:'money_plan__auth_userid', defaultval:'fun_getUserId()', anchor:'100%'}						]					},{						border:false,						columnWidth:0.5,						layout:'form',						style: 'padding-left:10px;',						items:[							{xtype:'trigger', fieldLabel:'实施部门', name:'money_plan__done_deptname',								anchor:'100%', triggerClass:'x-form-search-trigger',								maxLength:50, allowBlank:false, labelStyle:'color:#0000FF;', labelSeparator:'*', editable:false,								onTriggerClick: function() {									var selcfg = {pageType:'combogrid', nodeId:'sys_dept', layoutPage:'/public/layout/layout_tree.js', sourceField:'sys_dept.dept_name;dept_id', targetField:'money_plan.done_deptname;done_deptid', whereSql:"", whereValue:'', whereType:'', isSame:'0', isShowData:'1', isMoreSelect:'0',isReadonly:'1',fieldName:'money_plan.done_deptname'};									JxSelect.createSelectWin(selcfg, this, 'node_money_auth_form');								}},							{xtype:'textfield', fieldLabel:'授权人', name:'money_plan__auth_user', defaultval:'fun_getUserName()', readOnly:true, anchor:'100%', maxLength:20},							{xtype:'hidden', fieldLabel:'实施部门ID', name:'money_plan__done_deptid', anchor:'100%'}						]					}					]				}]			});						//添加缺省值			var form = printForm.getForm();			form.set('money_plan__auth_date', JxDefault.getToday());			form.set('money_plan__auth_userid', JxDefault.getUserId());			form.set('money_plan__auth_user', JxDefault.getUserName());						var self = this;			//创建对话框			var win = new Ext.Window({				title:	'批量授权',				layout:'fit',				width:550,				height:200,				resizable: false,				modal: true,				closeAction:'close',				items:[printForm],				buttons: [{					text:jx.base.ok,		//'确定'					handler:function(){						//数据校验						if (!form.isValid()) {							JxHint.alert(jx.event.datavalid);	//'请确保输入的数据正确完整！'							return;						}						self.exeAuth(planids, form);						win.close();					}				},{					text:jx.base.cancel,	//'取消'					handler:function(){win.close();}				}]			});			win.show();		},		createProject: function(){			var records = this.grid.getSelectionModel().getSelections();			if (!JxUtil.selected(records)) return;						for (var i = 0; i < records.length; i++) {				var authtype = records[i].get('money_plan__auth_type');				if (authtype == '') {					JxHint.alert('选择的记录中存在未分级授权的投资计划，不能分配项目！');					return true;				}			}						var self = this;			var hdcall = function() {				//取选择记录的主键值				var params = 'funid='+ self.define.nodeid;				for (var i = 0; i < records.length; i++) {					params += '&keyid=' + records[i].get(self.define.pkcol);				}				//设置请求的参数				params += '&pagetype=editgrid&eventcode=new_project';				//执行处理的内容				var endcall = function(data) {					//重新加载数据					self.grid.getStore().reload();				};				//发送请求				Request.postRequest(params, endcall);			};						Ext.Msg.confirm(jx.base.hint, '将对选择的投资计划进行项目分配，确定提交吗？', function(btn) {				if (btn == 'yes') hdcall();			});		}
	};
		
	return new Jxstar.GridNode(config);
}